home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <graphics.h>
- #include <dtypes.h>
- #include <alloc.h>
- #include <string.h>
- #include <conio.h>
-
- #include "loadpcx.h"
- #include "newshop.h"
- #include "ginput.h"
- #include <keybd.h>
-
- #define _LOAD 1
- #define _SAVE 2
- #define _SHELL 3
- #define _LEAVE 4
- #define _NAME 101
- #define _CHASSIS 102
- #define _WEAPONS 103
- #define _EXTRAS 104
- #define _EDIT 200
- #define _PLAYERS 301
- #define _NOTEAM 302
- #define _TEAMA 303
- #define _TEAMB 304
- #define _GRASS 401
- #define _SWAMP 402
- #define _WOODS 403
- #define _VILLAGE 404
- #define _BATTLE 500
-
- int chassis = 1;
- int weapons[] = {0,0,0,0,0,0,0,0,0,0,0,0};
- int extras[] = {0,0,0,0,0,0,0,0,0,0,0,0};
-
- PSTR menu0[] = {"FILE", "CONFIG", "EDIT", "TEAMS", "TERRAIN", "BATTLE", ""};
-
- PSTR menu1[] = {"LOAD",
- "SAVE",
- "SHELL",
- "EXIT",""};
-
- PSTR menu2[] = {"NAME",
- "CHASSIS",
- "WEAPONS",
- "EXTRA'S",""};
-
- PSTR menu4[] = {"PLAYERS",
- "NO TEAM",
- "TEAM A",
- "TEAM B",""};
-
- PSTR menu5[] = {"GRASS",
- "SWAMP",
- "WOODS",
- "VILLAGE",""};
-
- PSTR menu6[] = {"MACHINE 16mm",
- "MACHINE 8mm",
- "LASER",
- "CANNON",
- "ROCKET",
- "MINE",
- "RADIO MINE",""};
-
- PSTR smenu6[]= {"MACH16",
- "MACH 8",
- "LASER ",
- "CANNON",
- "ROCKET",
- "MINE ",
- "R MINE",""};
-
- PSTR menu7[] = {"LIGHTWEIGHT",
- "REGULATION",
- "HEAVYWEIGHT",""};
-
- PSTR frame[] = {"LIGHT",
- "REG.",
- "HEAVY",""};
-
- PSTR menu8[] = {"RADAR",
- "SCANNER",
- "SCOPE",
- "RADAR JAMMER",
- "RADIO TX",
- "RADIO RX",
- "MINE DETECT",
- "MINE SCOOP",""};
-
- PSTR smenu8[]= {"RADAR ",
- "SCAN ",
- "SCOPE ",
- "JAMMER",
- "TX ",
- "RX ",
- "DETECT",
- "SCOOP ",""};
-
- PSTR menu9[] = {"1 N",
- "2 N",
- "3 N",
- "4 N",
- "5 N",
- "6 N",
- "7 N",
- "8 N",
- "9 N",
- "0 N",""};
-
- TSS tnk;
-
- PSTR wind;
-
- BOOL fileerr = FALSE;
-
- BOOL saveit = TRUE;
- int select;
- BOOL picked;
- int lastpick = 0;
- char bbuf[20];
- int terrain = 0;
-
- /*-------------------------------------
- * Function : void main(void)
- * Purpose : Main calling module for NEWSHOP.C
- * Date : 02/19/1989 17:10:26
- */
- void main(void)
- {
- char buf[80];
-
- strcpy(bbuf,"NONAME");
-
- clrscr();
- cprintf("RoboTank was written (back in '89) by:\r\n");
- cprintf("Alexander Walsh (sandy@cs.mun.ca)\r\n\r\n");
- cprintf("Please distribute freely, email any comments you may have.\r\n");
- cprintf("Note: I will not be doing upgrades to this program\r\n");
- cprintf(" (it was a nice idea at the time)\r\n");
- while (!kbhit())
- ;
- (void) getch();
-
- register_bgi();
-
- set_screen_mode(4);
-
- Load_CGA_PCX("X4972.X90");
- while (!kbhit())
- ;
- (void) getch();
-
- #if 0
- Load_CGA_PCX("YYZ01.270");
- while (!kbhit())
- ;
- (void) getch();
- #endif
-
- Load_CGA_PCX("Z44YX.A20");
-
- select=0;
-
- while (select!=_LEAVE) {
-
- picked=FALSE;
- operate_topmenu(menu0);
- picked=FALSE;
-
- switch(select) {
- case _SAVE : to_TSS(&tnk);
- save_TSS(&tnk,bbuf);
- break;
-
- case _LOAD : get_a_tank_name(bbuf);
- fileerr=FALSE;
- load_TSS(&tnk,bbuf);
- if (!fileerr) {
- explode_TSS(&tnk);
- display_new_TSS();
- }
- break;
-
- case _EDIT : set_screen_mode(3);
- strcpy(buf,"ms.com ");
- strcat(buf,bbuf);
- strcat(buf,".txt");
-
- system(buf);
- set_screen_mode(4);
- Load_CGA_PCX("Z44YX.A20");
- display_new_TSS();
- break;
-
- case _WEAPONS: use_large_picklist(_WEAPONS,menu6);
- break;
-
- case _CHASSIS: use_large_picklist(_CHASSIS,menu7);
- break;
-
- case _EXTRAS : use_large_picklist(_EXTRAS ,menu8);
- break;
-
- case _PLAYERS: use_large_picklist(_PLAYERS,menu9);
- break;
-
- case _NOTEAM : use_large_picklist(_NOTEAM ,menu9);
- break;
-
- case _TEAMA : use_large_picklist(_TEAMA ,menu9);
- break;
-
- case _TEAMB : use_large_picklist(_TEAMB ,menu9);
- break;
-
- case _NAME : moveto(170,40); strcpy(bbuf,ggetline(8,bbuf));
- break;
-
- case _GRASS :
- case _SWAMP :
- case _WOODS :
- case _VILLAGE: setcolor(CGA_WHITE);
- bar(30,170,100,177);
- setcolor(BLACK);
- moveto(30,170);
- outtext(menu5[select-_GRASS]);
- terrain=select-_GRASS;
- break;
-
- case _BATTLE : prepare_for_battle();
- break;
- }
- }
-
- closegraph();
- } /* void main(void) */
-
- /*-------------------------------------
- * Function : void use_large_picklist(int table, PSTR list[])
- * Purpose : Operate the large picklist
- * Date : 02/20/1989 21:13:05
- */
- void use_large_picklist(int table, PSTR list[])
- {
- char name[10];
- int a;
-
- select=1;
- lastpick=0;
-
- while (select!=0) {
-
- picked=saveit=FALSE;
- select=0;
- operate_pulldown(26,50,list);
- saveit=TRUE;
-
- switch(table) {
-
- case _WEAPONS: display_pick(170,select,weapons,smenu6);
- break;
-
- case _EXTRAS : display_pick(245,select,extras ,smenu8);
- break;
-
- case _CHASSIS: if (select>0) {
- setcolor(CGA_WHITE);
- bar(250,40,300,50);
- setcolor(BLACK);
- moveto(250,40);
- outtext(frame[select-1]);
- chassis=select-1;
- }
- break;
-
- case _TEAMA : if (select>0)
- pickteam(select-1,'A');
- break;
-
- case _TEAMB : if (select>0)
- pickteam(select-1,'B');
- break;
-
- case _NOTEAM : if (select>0)
- pickteam(select-1,'N');
- break;
-
- case _PLAYERS: if (select>0) {
-
- strncpy(name,menu9[select-1]+2,8);
- name[8]=NULL;
-
- setcolor(CGA_WHITE);
- moveto(30,54+((select-1)*10));
- outtext(menu9[select-1]);
-
- get_a_tank_name(name);
-
- for (a=0; a<8; a++)
- *(menu9[select-1]+2+a)=' ';
-
- for (a=0; a<8 && name[a]!=NULL; a++)
- *(menu9[select-1]+2+a)=name[a];
-
- setcolor(CGA_RED);
- moveto(30,54+((select-1)*10));
- outtext(menu9[select-1]);
-
- }
- break;
- }
- }
-
- setcolor(CGA_WHITE);
- bar(26,52,130,160);
- } /* void use_large_picklist(int table, PSTR list[]) */
-
- /*-------------------------------------
- * Function : void pickteam(int pick, char new)
- * Purpose : Pick a new team and display results
- * Date : 02/26/1989 12:37:30
- */
- void pickteam(int pick, char new)
- {
- setcolor(CGA_WHITE);
- moveto(30,54+(pick*10));
- outtext(menu9[pick]);
-
- *(menu9[pick]+11)=new;
-
- setcolor(BLACK);
- moveto(30,54+(pick*10));
- outtext(menu9[pick]);
-
- } /* void pickteam(int pick, char new) */
-
- /*-------------------------------------
- * Function : void display_pick(int x, int pick, int set[], PSTR list[])
- * Purpose : Display the choice picked
- * Date : 02/20/1989 21:45:24
- */
- void display_pick(int x, int pick, int set[], PSTR list[])
- {
- int y;
-
- pick--;
-
- y=54+pick*10;
- moveto(x,y);
- setcolor(set[pick] ? CGA_WHITE : BLACK);
- outtext(list[pick]);
- set[pick] = set[pick] ? FALSE : TRUE;
-
- } /* void display_pick(int x, int pick, int set[], PSTR list[]) */
-
- /*-------------------------------------
- * Function : void operate_topmenu(PSTR op[])
- * Purpose : Operate the top portion of a pulldown menu system
- * Date : 02/19/1989 17:32:33
- */
- void operate_topmenu(PSTR op[])
- {
- int a, ni, ch;
- int x[20];
-
- ni=0; select=0; picked=FALSE;
-
- moveto(10,10); setcolor(BLACK);
-
- while (*op[ni]) {
- x[ni]=getx();
- outtext(op[ni++]);
- outtext(" ");
- }
-
- ch=' '; a=0;
-
- while (ch!=ESC && !picked) {
-
- select=a*100;
-
- light_word(x[a],10,op[a]);
-
- while(!kbhit())
- ;
-
- ch=getkey();
-
- if (ch==LF_ARR || ch==RT_ARR || ch==ESC || ch==DN_ARR || ch==CR) {
-
- if (ch!=DN_ARR)
- unlight_word(x[a],10,op[a]);
-
- if (ch==LF_ARR && a>0)
- a--;
- if (ch==RT_ARR && a<ni-1)
- a++;
- if (ch==DN_ARR || ch==CR) {
-
- lastpick=0;
-
- if (a==0)
- operate_pulldown(x[a],20,menu1);
-
- if (a==1)
- operate_pulldown(x[a],20,menu2);
-
- if (a==2 && ch==CR)
- picked=TRUE;
- if (a==3)
- operate_pulldown(x[a],20,menu4);
-
- if (a==4)
- operate_pulldown(x[a],20,menu5);
-
- if (a==5 && ch==CR)
- picked=TRUE;
- }
- }
- }
- unlight_word(x[a],10,op[a]);
-
- } /* void operate_topmenu(PSTR op[]) */
-
- /*-------------------------------------
- * Function : void operate_pulldown(int x, int y, PSTR op1[])
- * Purpose : Operate pulldown menu at (x,y)
- * Date : 02/19/1989 18:20:12
- */
- void operate_pulldown(int x, int y, PSTR op1[])
- {
- int a,ni, yc;
- int yy[20];
- int ch;
- int buf[1100];
-
- if (saveit) {
- getimage(x,y,x+65,y+45,buf);
- setcolor(CGA_WHITE);
- bar(x,y,x+65,y+45);
- setcolor(BLACK);
- rectangle(x,y,x+65,y+45);
- }
-
- ni=0; yc=y+4; x+=4;
-
- setcolor(BLACK);
- while (*op1[ni]) {
- moveto(x,yc);
- yy[ni]=yc;
- outtext(op1[ni++]);
- yc+=10;
- }
-
- a=lastpick; ch=' ';
-
- while (ch!=ESC && !picked) {
- light_word(x,yy[a],op1[a]);
-
- while (!kbhit())
- ;
-
- ch=getkey();
-
- if (ch==UP_ARR || ch==DN_ARR || ch==CR) {
-
- unlight_word(x,yy[a],op1[a]);
-
- if (ch==DN_ARR && a<ni-1)
- a++;
-
- if (ch==CR)
- picked=TRUE, select+=(a+1);
-
- if (ch==UP_ARR) {
- if (a==0 && saveit)
- ch=ESC;
- else if (a>0)
- a--;
- }
- }
- }
- if (saveit)
- putimage(x-4,y,buf,COPY_PUT);
-
- lastpick=a;
-
- } /* void operate_pulldown(int x, int y, PSTR op1[]) */
-
- /*-------------------------------------
- * Function : void light_word(int x, int y, char *s)
- * Purpose : Highlight word at (x,y)
- * Date : 02/19/1989 18:02:42
- */
- void light_word(int x, int y, char *s)
- {
- setcolor(BLACK);
- rectangle(x-2,y-2,x+textwidth(s),y+8);
- moveto(x,y);
- setcolor(CGA_RED);
- outtext(s);
- } /* void light_word(int x, int y, char *s) */
-
- /*-------------------------------------
- * Function : void unlight_word(int x, int y, char *s)
- * Purpose : Un-highlight word at (x,y)
- * Date : 02/19/1989 18:06:07
- */
- void unlight_word(int x, int y, char *s)
- {
- setcolor(CGA_WHITE);
- rectangle(x-2,y-2,x+textwidth(s),y+8);
- moveto(x,y);
- setcolor(BLACK);
- outtext(s);
- } /* void unlight_word(int x, int y, char *s) */
-
- /*-------------------------------------
- * Function : void register_bgi(void)
- * Purpose : Register the BGI driver for CGA
- * Date : 02/19/1989 17:16:18
- */
- void register_bgi(void)
- {
- int gm, gd;
-
- if (registerfarbgidriver(CGA_driver_far) < 0) {
- printf("Color graphics adapter required for this program\n");
- exit(1);
- };
-
- gm=CGAC1;
- gd=CGA;
-
- initgraph(&gd,&gm,"");
-
- if (graphresult()<0) {
- printf("Graphics driver initilization error, CGA required\n");
- exit(1);
- }
- } /* void register_bgi(void) */
-
- /*-------------------------------------
- * Function : void open_wind(void)
- * Purpose : Open dialog box window
- * Date : 02/26/1989 12:53:21
- */
- void open_wind(void)
- {
- int size;
-
- size=imagesize(70,70,250,160);
-
- if ((wind=malloc(size))==NULL) {
- printf("Cannot Malloc()\n");
- exit(1); /* Temp error */
- }
-
- getimage(70,70,250,160,wind);
-
- setfillstyle(CLOSE_DOT_FILL,CGA_RED);
- bar(70,70,250,160);
- setfillstyle(SOLID_FILL,CGA_WHITE);
- bar(80,80,240,150);
- setcolor(BLACK);
- rectangle(70,70,250,160);
- rectangle(80,80,240,150);
-
- } /* void open_wind(void) */
-
- /*-------------------------------------
- * Function : void get_a_tank_name(PSTR s)
- * Purpose : Get a tank name in string S
- * Date : 02/26/1989 13:07:47
- */
- void get_a_tank_name(PSTR s)
- {
- open_wind();
-
- moveto(90,90); outtext("ENTER TANK NAME:");
- moveto(100,110);
-
- ggetline(8,s);
-
- close_wind();
- } /* void get_a_tank_name(PSTR s) */
-
- /*-------------------------------------
- * Function : void close_wind(void)
- * Purpose : Close dialog box window
- * Date : 02/26/1989 12:57:05
- */
- void close_wind(void)
- {
- putimage(70,70,wind,COPY_PUT);
- free(wind);
- } /* void close_wind(void) */
-
- /*-------------------------------------
- * Function : void to_TSS(p_TSS t)
- * Purpose : Copy in-memory TSS to actual TSS structure
- * Date : 02/26/1989 16:02:30
- */
- void to_TSS(p_TSS t)
- {
- int a;
-
- t->t_chassis=chassis;
-
- for (a=0; a<10; a++) {
- t->t_weapons[a]=weapons[a];
- t->t_extras[a] =extras[a];
- }
- strcpy(t->name,"");
-
- } /* void to_TSS(p_TSS t) */
-
- /*-------------------------------------
- * Function : void explode_TSS(p_TSS t)
- * Purpose : Explode a TSS into it's component parts into memory
- * Date : 02/26/1989 16:13:08
- */
- void explode_TSS(p_TSS t)
- {
- int a;
-
- chassis=t->t_chassis;
-
- for (a=0; a<10; a++) {
- weapons[a]=t->t_weapons[a];
- extras[a] =t->t_extras[a];
- }
-
- } /* void explode_TSS(p_TSS t) */
-
- /*-------------------------------------
- * Function : void save_TSS(p_TSS t, PSTR fn)
- * Purpose : Save tank T to filename FN
- * Date : 02/26/1989 16:06:48
- */
- void save_TSS(p_TSS t, PSTR fn)
- {
- FILE *fp;
-
- if (*fn==NULL)
- return;
-
- if ((fp=fopen(fn,"wb"))==NULL) {
- printf("Cannot create file \n"); /* temp */
- exit(1);
- }
- fwrite(t,sizeof(TSS),1,fp);
-
- fclose(fp);
- } /* void save_TSS(p_TSS t, PSTR fn) */
-
- /*-------------------------------------
- * Function : void load_TSS(p_TSS t, PSTR fn)
- * Purpose : Load in a TSS structure from disk
- * Date : 02/26/1989 16:12:03
- */
- void load_TSS(p_TSS t, PSTR fn)
- {
- FILE *fp;
-
- if (*fn==NULL)
- return;
-
- if ((fp=fopen(fn,"rb"))==NULL) {
- show_error("CANNOT OPEN FILE");
- fileerr=TRUE;
- } else {
-
- fread(t,sizeof(TSS),1,fp);
-
- fclose(fp);
- }
- } /* void load_TSS(p_TSS t, PSTR fn) */
-
- /*-------------------------------------
- * Function : void display_new_TSS(void)
- * Purpose : Redraw screen with newly loaded tank specs
- * Date : 02/26/1989 16:22:52
- */
- void display_new_TSS(void)
- {
- int a;
-
- /* Clear picklist */
-
- setcolor(CGA_WHITE);
- bar(26,52,130,160);
-
- bar(170,54,220,150); /* weapons list */
- bar(245,54,300,150); /* extras list */
-
- bar(170,40,300,50); /* Tank name line */
-
- setcolor(BLACK);
-
- for (a=0; a<10; a++) {
- if (weapons[a]) {
- moveto(170, 54+a*10);
- outtext(smenu6[a]);
- }
- if (extras[a]) {
- moveto(245, 54+a*10);
- outtext(smenu8[a]);
- }
- }
-
- moveto(170,40); outtext(bbuf);
- moveto(250,40); outtext(frame[chassis]);
- } /* void display_new_TSS(void) */
-
- /*-------------------------------------
- * Function : void show_error(char *s)
- * Purpose : Display an error in window
- * Date : 02/26/1989 16:45:03
- */
- void show_error(char *s)
- {
- open_wind();
- moveto(85,100);
-
- outtext(s);
- moveto(110,120);
-
- outtext("PRESS ENTER ");
- ggetline(1," ");
-
- close_wind();
-
- } /* void show_error(char *s) */
-
- /*-------------------------------------
- * Function : void prepare_for_battle(void)
- * Purpose : Get ready to call shop.exe for the big fight
- * Date : 02/26/1989 16:37:15
- */
- void prepare_for_battle(void)
- {
- int a;
- int nc;
- BOOL any;
- TSS player;
- char nm[20];
- char buf[50];
- FILE *fp;
- BOOL good=TRUE;
-
- if ((fp=fopen("BATTLE.DAT","wb"))==NULL) {
- show_error("DISK ERROR");
- return;
- }
-
- any=FALSE;
- nc=0;
-
- for (a=0; a<10; a++)
- if (*(menu9[a]+2) != ' ')
- any=TRUE, nc++;
-
- if (!any) {
- show_error("NO PLAYERS");
- good=FALSE;
- } else {
- fileerr=FALSE;
-
- putw(nc,fp); /* Write out the number of contestants */
- putw(terrain,fp); /* Where are we fighting ??? */
-
- for (a=0; a<10 && !fileerr; a++)
- if (*(menu9[a]+2) != ' ') {
-
- strncpy(nm, menu9[a]+2, 8);
- nm[8]=NULL;
-
- fileerr=FALSE;
- load_TSS(&player,nm);
-
- if (fileerr) {
- sprintf(buf,"BAD NAME \"%s\"",nm);
- show_error(buf);
- good=FALSE;
- } else {
-
- switch (*(menu9[a]+11)) {
- case 'N' : player.team=0; break;
- case 'A' : player.team=1; break;
- case 'B' : player.team=2; break;
- }
-
- strcpy(player.name,nm); /* Save tank's name */
-
- fwrite(&player,sizeof(TSS),1,fp); /* Write out player */
- }
- }
- }
-
- fclose(fp);
-
- if (good) {
- set_screen_mode(3);
- system("host.exe");
- set_screen_mode(4);
- Load_CGA_PCX("Z44YX.A20");
- display_new_TSS();
- }
- } /* void prepare_for_battle(void) */